# $Id: TextArea.pm,v 1.2 2004/04/27 14:26:22 ibo Exp $
package CGI::FOGE2::TextArea;

use strict;
use CGI::FOGE2::Tools;

our @ISA = qw(CGI::FOGE2::Question);

sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;

    my %args = @_;
    my @mandatory_keys = ('title', 'id');
    my $self =
      {
       id            => undef,
       textlength    => 32,
       textheight    => 5,
       default       => undef,
       title         => undef,	# was: label
       ismandatory   => 0,
       isvalidregexp => undef,
       validate      => undef, # func. returning string or false
       stats         => [CGI::FOGE2::StatsFree->new()]
      };
    bless ($self, $class);
    $self->_construct(\%args, \@mandatory_keys);

    # private fields
    $self->{errmsg} = undef;
    return $self;
}

####### BRICOLAGE #############
sub suitable_stats {
    my $self = shift;
    my %stat_constructors = ('StatsFree' => sub {CGI::FOGE2::StatsFree->new()},
			     );
    return \%stat_constructors;
}
###############################

sub serve {
    my $self = shift;
    my $id = $self->{id};
    my $ismandatory = $self->{ismandatory};
    my $names = $self->generate_field_names();
    my $name = $names->[0];

    my %line = (-columns => $self->{textlength}, 
                -rows    => $self->{textheight},
                -name    => $name);

    if (defined $self->{default}) {
	$line{-default} = $self->{default};
    }

    return table3cols($self->{title},
		     $self->{ismandatory},
		     CGI::textarea(%line));
}

sub stats {
    my $self = shift;
}

sub as_text {
    my $self = shift;
    my ($ign, $indent) = @_;
    my $out = $self->as_text_header(@_);

    my $fmt = "%s    TextArea: [%-016s]\n";
    $out .= sprintf $fmt, $indent, $self->{default} || '_' x 16;

    return $out;
}

1;
